package com.hllxd.hism.star.basic.service.schedule;

//import com.bj58.job.core.biz.model.ReturnT;
//import com.bj58.job.core.handler.IJobHandler;
//import com.bj58.job.core.handler.annotation.JobHandler;
//import com.bj58.job.core.log.WJobLogger;
//import com.bj58.zp.cdata.star.basic.service.dao.mapper.mis.PermissionInfoMapper;
//import com.bj58.zp.cdata.star.basic.service.model.AllUserPermission;
//import com.bj58.zp.cdata.star.basic.service.model.PermissionInfo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Set;

/**
 * 任务Handler示例（Bean模式）     *
 * * 开发步骤：
 * * 1、继承"IJobHandler"：“IJobHandler”；
 * * 2、注册到执行器工厂：添加“@JobHandler(value="自定义jobhandler名称")”注解，注解value值对应的是调度中心新建任务的JobHandler属性的值。
 * * 3、执行日志：需要通过 "WJobLogger.log" 打印执行日志;
 */
//@JobHandler(value = "permissionCacheJobHandler")
//如果是spring方式初始化的 需要加上component注解
//@Component
//public class PermissionCacheJobHandler extends IJobHandler {
//
//    @Autowired
//    private PermissionInfoMapper permissionInfoMapper;
//
//    private static final String KEY_PREFIX = "star_permission_all_user_";
//    private static final String ALL_PERMISSION_KEY = "star_permission_all_set";
//    @Autowired
//    private RedisTemplate<String, String> redisTemplate;
//
//    @Override
//    public ReturnT<String> execute(String param) throws Exception {
//        WJobLogger.log("W-JOB, start.permissionCacheJobHandler");
//
//        List<PermissionInfo> allPermission = permissionInfoMapper.getAllPermission();
//        redisTemplate.delete(ALL_PERMISSION_KEY);
//
//        Set<String> userKeys = redisTemplate.keys(KEY_PREFIX + "*");
//        if (userKeys != null) {
//            for (String userKey : userKeys) {
//                redisTemplate.delete(userKey);
//            }
//        }
//
//        List<AllUserPermission> allUserPermission = permissionInfoMapper.getAllUserPermission();
//        for (AllUserPermission userPermission : allUserPermission) {
//            String pUserName = userPermission.getUserName();
//            if (pUserName != null) {
//                redisTemplate.opsForHash().put(KEY_PREFIX + pUserName, userPermission.getFunctionLabel(), userPermission.getFunctionItem());
//            }
//        }
//
//        //处理星号标签
//        List<AllUserPermission> allUserStarPermission = permissionInfoMapper.getAllUserStarPermission();
//        for (AllUserPermission userPermission : allUserStarPermission) {
//            String userName = userPermission.getUserName();
//            String functionLabels = userPermission.getFunctionLabels();
//            String[] labelsArr = functionLabels.split(",");
//            for (String label : labelsArr) {
//                int i = label.indexOf("*");
//                if (i >= 0) {
//                    String labelPrefix = label.substring(0, i);
//                    List<PermissionInfo> permissionInfos = permissionInfoMapper.getPermissionInfoByLabelPrefix(labelPrefix);
//                    for (PermissionInfo permissionInfo : permissionInfos) {
//                        if (userName != null) {
//                            redisTemplate.opsForHash().put(KEY_PREFIX + userName, permissionInfo.getFunctionLabel(), permissionInfo.getFunctionItem());
//                        }
//                    }
//                }
//            }
//        }
//
//        for (PermissionInfo permissionInfo : allPermission) {
//            String functionItem = permissionInfo.getFunctionItem();
//            Integer permissionType = permissionInfo.getPermissionType();
//            if (permissionType == 0) {
//                redisTemplate.opsForSet().add(ALL_PERMISSION_KEY, functionItem);
//            }
//        }
//
//
//        WJobLogger.log("W-JOB, end.permissionCacheJobHandler");
//        return SUCCESS;
//    }

//}
